package com.denlaku.longan.util;

import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

/**
 * @author tianx
 */
public final class Sets {

    public static <T> Set<T> empty() {
        return ofSize(0);
    }

    public static <T> Set<T> ofSize(int size) {
        return new HashSet<>(Math.max(size, 0));
    }

    @SafeVarargs
    public static <T> Set<T> of(T ...values) {
        if (values == null) {
            return empty();
        }
        Set<T> set = ofSize(values.length);
        Collections.addAll(set, values);
        return set;
    }

    public static <T> Set<T> of(Collection<T> values) {
        if (values == null || values.isEmpty()) {
            return empty();
        }
        Set<T> set = ofSize(values.size());
        set.addAll(values);
        return set;
    }

    private Sets() {}
}
